package homework.day01;

import java.io.File;
import java.io.FileFilter;

/**
 *
 * 列出目录中把所有名字包含s的子项
 *
 * 使用匿名内部类和lambda两种写法
 *
 * FileFilter 文件过滤器
 * accept 接受
 *
 * Author：毕龙
 * Date: 2022/9/7 11:16
 */
public class Test02 {
    public static void main(String[] args) {
        File dir = new File("java-study-se");
        if(dir.isDirectory()){
            File[] subs = dir.listFiles(new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    return pathname.getName().contains("s");
                }
            });
            for (int i = 0; i < subs.length; i++) {
                System.out.println(subs[i].getName());
            }
        }
        System.out.println("=====lambda表达式=====");
        if (dir.isDirectory()){
            File[] subs = dir.listFiles(f -> f.getName().contains("s"));
            for (int i = 0; i < subs.length; i++) {
                System.out.println(subs[i].getName());
            }
        }
    }
}
